﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hfm.Core.DataAccess.Parameters;
using Hfm.Common.Entity.Parameters;

namespace Hfm.Core.BusinessManager.Parameters
{
    public class ParametersManager
    {
        protected readonly ParametersData parametersData;

        private static Object Lock_Obj_SONumber = new Object();


        public ParametersManager(ParametersData dataAccess)
        {
            this.parametersData = dataAccess;
        }

        public virtual string GetOrderNumber()
        {
            lock (Lock_Obj_SONumber)
            {
                string SO = string.Empty;

                int inumber = parametersData.SetValue();

                string snumber = null;

                if (inumber.ToString().Length == 1)
                {
                    snumber = "00" + inumber.ToString();
                }
                else if (inumber.ToString().Length == 2)
                {
                    snumber = "0" + inumber.ToString();
                }
                else
                {
                    snumber = inumber.ToString();
                }

                DateTime now = DateTime.Now;

                string OrderNumberYear = now.Year % 100 < 10 ? ("0" + (now.Year % 100).ToString()) : (now.Year % 100).ToString();
                string OrderNumberMonth = now.Month < 10 ? ("0" + now.Month.ToString()) : now.Month.ToString();
                string OrderNumberDay = now.Day < 10 ? ("0" + now.Day.ToString()) : now.Day.ToString();

                string OrderNumber = OrderNumberYear + OrderNumberMonth + OrderNumberDay + snumber;
                return OrderNumber;
            }
        }
    }
}
